<?php
$this->breadcrumbs=array(
    'Quản trị'=>array('/admin'),
    'Bình luận'=>array('index'),
    'Quản lý',
);



Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('comments-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>

<h1>Quản lý bình luận</h1>


<?php /*echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); */?><!--
<div class="search-form" style="display:none">
    <?php /*$this->renderPartial('_search',array(
    'model'=>$model,
)); */?>
</div>--><!-- search-form -->

<?php
function viewItem($data){
    $link = '';
    switch($data->item_type)
    {
        case 'training':
            $link = CHtml::link($data->training->name,Yii::app()->createUrl('training/view',array('vid'=>$data->training->id, 'name' => Yii::app()->func->safeTitle($data->training->name))),array('target'=>'_blank'));
            break;
        case 'video':
            $link = CHtml::link($data->video->title,Yii::app()->createUrl('video/view',array('vid'=>$data->video->id, 'name' => Yii::app()->func->safeTitle($data->video->title))),array('target'=>'_blank'));
            break;
        case 'song':
            $link = CHtml::link($data->song->title,Yii::app()->createUrl('song/view',array('id'=>$data->song->id, 'title' => Yii::app()->func->safeTitle($data->song->title))),array('target'=>'_blank'));
            break;
        case 'news':
            $link = CHtml::link($data->news->title,Yii::app()->createUrl('news/view',array('id'=>$data->news->id, 'title' => Yii::app()->func->safeTitle($data->news->title))),array('target'=>'_blank'));
            break;
        case 'product':
            $link = CHtml::link($data->product->name,Yii::app()->createUrl('product/view',array('id'=>$data->product->id, 'title' => Yii::app()->func->safeTitle($data->product->name))),array('target'=>'_blank'));
            break;
        case 'static_page':
            $link = CHtml::link($data->static_page->name,Yii::app()->createUrl('page/view',array('id'=>$data->prstatic_pageoduct->id, 'title' => Yii::app()->func->safeTitle($data->static_page->title))),array('target'=>'_blank'));
            break;
    }
    return $link;
}
$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'comments-grid',
    'dataProvider'=>$model->search(),
    //'filter'=>$model,
    'columns'=>array(
        //'id',
        array(
            'name'=>'user_id',
            'value'=>'$data->user->username',
        ),
        array(
            'name'=>'item_id',
            'value'=>'viewItem($data)',
            'type'=>'html'
        ),
        //'item_type',
        'content',
        array(
            'name'=>'create_time',
            'value'=>'date("d/m/Y H:i",$data->create_time)'
        ),
        /*
          'status',
          */
        array
        (
            'class'=>'CButtonColumn',
            'template'=>'{delete}',
        )
    ),
)); ?>
